package com.lq.springcloud.controller;

import com.lq.springcloud.service.PaymentHystrixService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@DefaultProperties(defaultFallback = "payment_Global_FallbackMethod")//默认熔断降级方法
public class OrderHystrixController {
    @Resource
    private PaymentHystrixService  paymentHystrixService;


    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfoOk(@PathVariable("id") Long id){
        String result=paymentHystrixService.paymentInfoOk(id);
        log.info("+++++++++++++result"+result);
        return result;
    }

    //    @HystrixCommand(fallbackMethod = "paymentInfoFalseHandler",commandProperties = {
//            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value = "1500")
//    })//特定降级方法
    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
    @HystrixCommand
    public String paymentInfoFalse(@PathVariable("id") Long id){
        String result=paymentHystrixService.paymentInfoFalse(id);
        return result;
    }

    public String  paymentInfoFalseHandler(@PathVariable("id") Long id){
        return "我是消费者80，对方支付系统繁忙请10秒后再试试或者自己运行报错请检查自己";
    }

    public String  payment_Global_FallbackMethod(){
        return "通用降级方法";
    }
}
